import Vue from 'vue'
import VueRouter from 'vue-router'
import Login from "@/views/register/Login.vue";
import Home from "@/views/home/Home.vue";
import SystemSetting from "@/views/my/tools/SystemSetting.vue";
import Feedback from "@/views/my/tools/Feedback.vue";
import WashCarCourse from "@/views/my/tools/WashCarCourse.vue";
import ServiceAgreement from "@/views/my/tools/ServiceAgreement.vue";
import Instructions from "@/views/my/tools/Instructions.vue";
import Register from "@/views/register/Register.vue";
import Pass from "@/views/register/Pass.vue";
import AddressManagement from "@/views/my/tools/AddressManagement.vue";
import AddressEdit from "@/views/my/tools/AddressEdit.vue";
import StationDetail from "@/views/location/StoreDetail/StationDetail.vue";
import StoreMap from "@/views/location/StoreDetail/StoreMap.vue";
import AboutUs from "@/views/my/tools/AboutUs.vue";
import MyCar from "@/views/my/common/MyCar.vue";
import CarBindStore from "@/views/my/common/CarBindStore.vue";
import StoreBind from "@/views/my/common/StoreBind.vue";
import StoreDetail from "@/views/my/common/StoreDetail.vue";
import Integral from "@/views/my/common/Integral.vue";
import DetailIntegral from "@/views/my/common/DetailIntegral.vue";
import BindCar from "@/views/home/bindcar/BindCar.vue";
import Selectastore from "@/views/home/bindcar/Selectastore.vue";
import Balance from "@/views/my/common/Balance.vue";
import DetailBalance from "@/views/my/common/DetailBalance.vue";
import Payment from "@/views/my/common/Payment.vue";
import PayChooseStore from "@/views/my/common/PayChooseStore.vue";
import SelectARecord from "@/views/home/settlementisopen/SelectARecord.vue";
import SettlementIsOpen from "@/views/home/settlementisopen/SettlementIsOpen.vue";
import CarWashTicket from "@/views/home/settlementisopen/CarWashTicket.vue";
import BindCarOfStore from "@/views/location/StoreDetail/BindCarOfStore.vue";
import CarWashCalendar from "@/views/home/settlementisopen/CarWashCalendar.vue";
import StoreComment from "@/views/home/comment/StoreComment.vue";

Vue.use(VueRouter)

const routes = [
    {
        path: '/',
        name: 'home',
        redirect: "/home",
    },
    {
        path: "/login",
        name: "Login",
        component: Login
    },
    //标签栏主页
    {
        path: "/home",
        name: "Home",
        component: Home
    },
    //标签栏附件门店
    {
        path: '/nearByStore',
        name: 'NearByStore',
        component: () => import('../views/location/NearByStore.vue')
    },
    //标签栏商城
    {
        path: '/Store',
        name: 'Store',
        component: () => import('../views/store/Store.vue')
    },
    //标签栏我的
    {
        path: '/my',
        name: 'My',
        component: () => import('../views/my/My.vue')
    },

    {
        path: '/unpaid',
        name: 'Unpaid',
        component: () => import('../views/my/order/Unpaid.vue')
    },
    //我的订单，去评价
    {
        path: '/comment',
        name: 'Comment',
        component: () => import('../views/my/order/OrderComment')
    },
    //我的订单，查看订单
    {
        path: '/orderDetailed',
        name: 'OrderDetailed',
        component: () => import('../views/my/order/OrderDetailed')
    },
    //我的订单，微信支付
    {
        path: '/pay',
        name: 'Name',
        component: () => import('../views/my/order/WechatPay.vue')
    },
    //我的订单，支付成功
    {
        path: '/PayFinish',
        name: 'PayFinish',
        component: () => import('../views/my/order/PayFinish.vue')
    },

    //个人信息
    {
        path: '/personInfo',
        name: 'PersonInfo',
        component: () => import('../views/my/info/PersonInfo.vue')
    },
    //系统设置
    {
        path: '/systemSetting',
        name: 'SystemSetting',
        component: SystemSetting
    },
    //意见反馈
    {
        path: '/feedback',
        name: 'Feedback',
        component: Feedback
    },
    //洗车教程
    {
        path: '/washCarCourse',
        name: 'WashCarCourse',
        component: WashCarCourse
    },
    //服务协议
    {
        path: '/serviceAgreement',
        name: 'ServiceAgreement',
        component: ServiceAgreement
    },
    //操作指南
    {
        path: '/instructions',
        name: 'Instructions',
        component: Instructions
    },
    {
        path: '/StoreInformation',
        name: 'StoreInformation',
        component: () => import('../views/location/StoreDetail/StoreInformation.vue')
    },
    //商品详情
    {
        path: '/SingleCommodity',
        name: 'SingleCommodity',
        component: () => import('../views/store/SingleCommodity.vue')
    },
    //商品查询展示所有商品
    {
        path: '/SearchPage',
        name: 'SearchPage',
        component: () => import('../views/store/storeSearch/SearchPage.vue')
    },
    //商品用户评价
    {
        path: '/Evaluate',
        name: 'Evaluate',
        component: () => import('../views/store/Evaluate.vue')
    },
    //确认订单
    {
        path: '/SingleOrder',
        name: 'SingleOrder',
        component: () => import('../views/store/SingleOrder.vue')
    },
    //门店信息
    {
        path: '/StoreCheck',
        name: 'StoreCheck',
        component: () => import('../views/store/StoreCheck.vue')
    },
    //商品下单页面
    {
        path: '/AddressManagementStore',
        name: 'AddressManagementStore',
        component: () => import('../views/store/AddressManagementStore.vue')
    },
    //评论详情
    {
        path: '/EvaluateDetail',
        name: 'EvaluateDetail',
        component: () => import('../views/location/StoreDetail/EvaluateDetail.vue')
    },
    //添加地址
    {
        path: '/addressManagement',
        name: 'AddressManagement',
        component: AddressManagement
    },
    //添加地址
    {
        path: '/addressEdit',
        name: 'AddressEdit',
        component: AddressEdit
    },
    //注册
    {
        path: '/register',
        name: 'Register',
        component: Register
    },
    //忘记密码
    {
        path: '/pass',
        name: 'Pass',
        component: Pass
    },
    //工位详细信息
    {
        path: '/StationDetail',
        name: 'StationDetail',
        component: StationDetail
    },
    //地图详细信息
    {
        path: '/StoreMap',
        name: 'StoreMap',
        component: StoreMap
    },
    //我的车辆
    {
        path: '/myCar',
        name: 'MyCar',
        component: MyCar
    },
    //关于我们
    {
        path: '/AboutUs',
        name: 'AboutUs',
        component: AboutUs
    },
    //车辆绑定的门店
    {
        path: '/carBindStore',
        name: 'CarBindStore',
        component: CarBindStore
    },
    //门店绑定
    {
        path: '/StoreBind',
        name: 'StoreBind',
        component: StoreBind
    },
    //门店详情
    {
        path: '/StoreDetail',
        name: 'StoreDetail',
        component: StoreDetail
    },
    //我的积分
    {
        path: '/integral',
        name: 'Integral',
        component: Integral
    },
    //积分明细
    {
        path: '/detailIntegral',
        name: 'DetailIntegral',
        component: DetailIntegral
    },
    //绑定车辆
    {
        path: '/BindCar',
        name: 'BindCar',
        component: BindCar
    },
    //选择绑定门店
    {
        path: '/Selectastore',
        name: 'Selectastore',
        component: Selectastore
    },
    //余额
    {
        path: '/balance',
        name: 'Balance',
        component: Balance
    },
    //余额
    {
        path: '/detailBalance',
        name: 'DetailBalance',
        component: DetailBalance
    },
    //充值页面
    {
        path: '/payment',
        name: 'Payment',
        component: Payment
    },
    //选择充值门店
    {
        path: '/payChooseStore',
        name: 'PayChooseStore',
        component: PayChooseStore
    },
    //选择结算车辆
    {
        path: '/SelectARecord',
        name: 'SelectARecord',
        component: SelectARecord
    },
    //付款界面
    {
        path: '/SettlementIsOpen',
        name: 'SettlementIsOpen',
        component: SettlementIsOpen
    },
    //优惠券
    {
        path: '/CarWashTicket',
        name: 'CarWashTicket',
        component: CarWashTicket
    },
    //选择要洗的车
    {
        path: '/BindCarOfStore',
        name: 'BindCarOfStore',
        component: BindCarOfStore
    },
    //洗车日历
    {
        path: '/carWashCalendar',
        name: 'CarWashCalendar',
        component: CarWashCalendar
    },
    //店铺评价
    {
        path: '/StoreComment',
        name: 'StoreComment',
        component: StoreComment
    }
]

const router = new VueRouter({
    routes
})

// 获取原型对象push函数
const originalPush = VueRouter.prototype.push

// 获取原型对象replace函数
const originalReplace = VueRouter.prototype.replace

// 修改原型对象中的push函数
VueRouter.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}

// 修改原型对象中的replace函数
VueRouter.prototype.replace = function replace(location) {
    return originalReplace.call(this, location).catch(err => err)
}

//前置路由守卫
router.beforeEach((to, from, next) => {
    let path = to.path;
    if (path === "/" || path === "/login" || path === "/pass" || path === "/register" || path === "/home" || path === "/store" || path === "/my" || path === "/nearByStore") {
        next();
    } else {
        let token = sessionStorage.getItem("token");
        if (token) {
            next();
        } else {
            next("/login");
        }
    }
})

export default router
